//
//  RABookDetailTopCell.m
//  ReadApp
//
//  Created by 飞猪 on 2018/11/8.
//  Copyright © 2018年 Facebook. All rights reserved.
//

#import "RABookDetailTopCell.h"
#import "RABookDetailModel.h"

@interface RABookDetailTopCell ()

@property (nonatomic, strong) UIImageView *titleImg;

@property (nonatomic, strong) UILabel *titleLab;

@property (nonatomic, strong) UILabel *statusLab;
@property (nonatomic, strong) UILabel *categoryLab;
@property (nonatomic, strong) UILabel *editorLab;
@property (nonatomic, strong) UILabel *countLab;

@property (nonatomic, strong) UIView *btmLine;

@end

@implementation RABookDetailTopCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  if (self) {
    [self addSubViews];
  }
  return self;
}

- (void)addSubViews {
  
  self.backgroundColor = [UIColor whiteColor];
  self.contentView.backgroundColor = [UIColor whiteColor];
  self.selectionStyle = UITableViewCellSelectionStyleNone;
  
  [self.contentView addSubview:self.titleImg];
  [self.contentView addSubview:self.titleLab];
  [self.contentView addSubview:self.statusLab];
  [self.contentView addSubview:self.categoryLab];
  [self.contentView addSubview:self.editorLab];
  [self.contentView addSubview:self.countLab];
  [self.contentView addSubview:self.btmLine];
  
  [self.titleImg mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.bottom.left.mas_equalTo(self.contentView).mas_equalTo(UIEdgeInsetsMake(10, 10, 10, 10));
    make.height.mas_equalTo(136.f);
    make.width.mas_equalTo(self.titleImg.mas_height).dividedBy(1.3);
  }];
  
  [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
    make.right.mas_lessThanOrEqualTo(-10);
    make.top.mas_equalTo(self.titleImg.mas_top).mas_offset(0);
    make.left.mas_equalTo(self.titleImg.mas_right).mas_offset(10);
  }];
  
  [self.statusLab mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(self.titleLab.mas_left).mas_offset(0);
    make.right.mas_lessThanOrEqualTo(-10);
    make.bottom.mas_equalTo(self.categoryLab.mas_top).mas_offset(-6);
  }];
  
  [self.categoryLab mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(self.titleLab.mas_left).mas_offset(0);
    make.right.mas_lessThanOrEqualTo(-10);
    make.bottom.mas_equalTo(self.editorLab.mas_top).mas_offset(-6);
  }];
  
  [self.editorLab mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(self.titleLab.mas_left).mas_offset(0);
    make.right.mas_lessThanOrEqualTo(-10);
    make.bottom.mas_equalTo(self.countLab.mas_top).mas_offset(-6);
  }];
  
  [self.countLab mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(self.titleLab.mas_left).mas_offset(0);
    make.right.mas_lessThanOrEqualTo(-10);
    make.bottom.mas_equalTo(self.titleImg.mas_bottom).mas_offset(0);
  }];
  
  [self.btmLine mas_makeConstraints:^(MASConstraintMaker *make) {
    make.right.left.bottom.mas_equalTo(0);
    make.height.mas_equalTo(0.5);
  }];
  
}

- (void)setModel:(RABookDetailModel *)model {
  _model = model;
  
  [self.titleImg sd_setImageWithURL:[NSURL URLWithString:_model.bookCover] placeholderImage:[UIImage imageNamed:@"default_placeImage"]];
  
  self.titleLab.text = _model.bookName;
  
  self.statusLab.text = [NSString stringWithFormat:@"状态 %@", _model.status];
  self.categoryLab.text = [NSString stringWithFormat:@"分类 %@", _model.bookClass];
  self.editorLab.text = [NSString stringWithFormat:@"作者 %@", _model.bookAuthor];
  self.countLab.text = [NSString stringWithFormat:@"字数 %@", _model.words];
  
}

- (UILabel *)titleLab {
  if (!_titleLab) {
    _titleLab = [UILabel new];
    _titleLab.font = [UIFont systemFontOfSize:14.f];
    _titleLab.textColor = [UIColor blackColor];
    //    _titleLab.text = @"本期热推";
  }
  return _titleLab;
}

- (UILabel *)statusLab {
  if (!_statusLab) {
    _statusLab = [UILabel new];
    _statusLab.font = [UIFont systemFontOfSize:13.f];
    _statusLab.textColor = [UIColor lightGrayColor];
    //    _titleLab.text = @"本期热推";
  }
  return _statusLab;
}

- (UILabel *)categoryLab {
  if (!_categoryLab) {
    _categoryLab = [UILabel new];
    _categoryLab.font = [UIFont systemFontOfSize:13.f];
    _categoryLab.textColor = [UIColor lightGrayColor];
    //    _titleLab.text = @"本期热推";
  }
  return _categoryLab;
}

- (UILabel *)editorLab {
  if (!_editorLab) {
    _editorLab = [UILabel new];
    _editorLab.font = [UIFont systemFontOfSize:13.f];
    _editorLab.textColor = [UIColor lightGrayColor];
    //    _titleLab.text = @"本期热推";
  }
  return _editorLab;
}

- (UILabel *)countLab {
  if (!_countLab) {
    _countLab = [UILabel new];
    _countLab.font = [UIFont systemFontOfSize:13.f];
    _countLab.textColor = [UIColor lightGrayColor];
    //    _titleLab.text = @"本期热推";
  }
  return _countLab;
}

- (UIImageView *)titleImg {
  if (!_titleImg) {
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
    imageView.userInteractionEnabled = NO;
    
    _titleImg = imageView;
  }
  return _titleImg;
}

- (UIView *)btmLine {
  if (!_btmLine) {
    _btmLine = [[UIView alloc] init];
    _btmLine.backgroundColor = UIColorHex(ebebeb);
  }
  return _btmLine;
}

@end
